package com.vdong.shardingorder.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vdong.shardingorder.entity.VdGoods;
import com.vdong.shardingorder.mapper.VdGoodsMapper;
import com.vdong.shardingorder.service.IVdGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vdong.shardingorder.utils.SnowflakeIdWorkerUtils;
import com.vdong.shardingorder.vo.goods.req.AddGoodsReqVO;
import com.vdong.shardingorder.vo.goods.req.ListGoodsReqVO;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 宋发准
 * @since 2021-08-31
 */
@Service
@DS("master")
public class VdGoodsServiceImpl extends ServiceImpl<VdGoodsMapper, VdGoods> implements IVdGoodsService {


    @Override
    public Boolean addGoods(AddGoodsReqVO req) {
        VdGoods goods = new VdGoods();
        BeanUtil.copyProperties(req, goods);
        goods.setId(SnowflakeIdWorkerUtils.genId());
        goods.setCreateTime(LocalDateTime.now());
        goods.setUpdateTime(LocalDateTime.now());
        return save(goods);
    }

    @Override
    public IPage<VdGoods> listGoods(ListGoodsReqVO req) {

        IPage<VdGoods> page = new Page<>(req.getPage(), req.getSize());
        IPage<VdGoods> p = page(page);

        return p;

    }
}
